laravel global scope

84

public function boot()
    {
        parent::boot();

        Route::bind('project', function($id) {
            return \App\Project::withoutGlobalScopes()->findOrFail($id);
        });
    }
Schema::table('flights', function (Blueprint $table) {
    $table->softDeletes();
});
SET configuration variables at runtime:
class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        View::share('key', 'value');
        Schema::defaultStringLength(191);
        $company=DB::table('company')->where('id',1)->first();
        config(['yourconfig.company' => $company]);
    }
}

USE:
config('yourconfig.company');
<?php
 
namespace App\Models;
 
use Illuminate\Database\Eloquent\Model;
 
class User extends Model
{
    /**
     * Scope a query to only include popular users.
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopePopular($query)
    {
        return $query->where('votes', '>', 100);
    }
 
    /**
     * Scope a query to only include active users.
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @return void
     */
    public function scopeActive($query)
    {
        $query->where('active', 1);
    }
}
protected static function boot()
    {
        parent::boot();
  
        static::addGlobalScope(new ArchiveScope);
    }

Comments

Submit
0 Comments